package com.mirror.utils;

import android.os.Environment;
import android.os.StatFs;

/**
 * @Title: 检查存储空间大小
 * @Version: 1.0
 * @Author: QiYin
 * @Date: 2013-2-22
 * @Company: EmagSoftware
 */
public class MemoryChecker {

    /**
     * 检查内存储可用存储空间/字节
     * @return 字节数
     */
    public static long getAvailableInternalMemorySize() {
        StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
        return stat.getAvailableBlocks() * stat.getBlockSize();
    }

    /**
     * 检查内存储总共存储空间/字节
     * @return 字节数
     */
    public static long getTotalInternalMemorySize() {
        StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
        return stat.getBlockCount() * stat.getBlockSize();
    }

    /**
     * 检查外存储卡是否可用
     * @return 是否可用
     */
    public static boolean externalMemoryAvailable() {
        return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    }

    /**
     * 检查外存储可用空间/字节
     * @return 字节数
     */
    public static long getAvailableExternalMemorySize() {
        if (externalMemoryAvailable()) {
            StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
            return stat.getAvailableBlocks() * stat.getBlockSize();
        } else {
            return -1;
        }
    }

    /**
     *  检查内存储总共存储空间/字节
     * @return 字节数
     */
    public long getTotalExternalMemorySize() {
        if (externalMemoryAvailable()) {
            StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
            return stat.getBlockCount() * stat.getBlockSize();
        } else {
            return -1;
        }
    }
}
